// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue';
import Es6Promise from 'es6-promise'
import App from './App';
import router from './router';
import store from './store';
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/main.scss'
import global_ from './view/Global'
import Validator from 'vue-validator'
import './assets/iconfont/iconfont.css'
import AMap from 'vue-amap'

import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import VueQuillEditor from 'vue-quill-editor'

// import '../theme/index.css'
Vue.use(AMap);
Vue.use(Validator)
Vue.prototype.GLOBAL = global_;
Vue.use(ElementUI)
Vue.config.productionTip = false;
Vue.prototype.HOST = '/api';
Vue.use(VueQuillEditor);
/* eslint-disable no-new */
// var api = process.env.API_URL;
Es6Promise.polyfill();

/**权限指令**/
Vue.directive('hasResource', {
  bind: function (el, binding) {
    Vue.nextTick(function () {
      if (!Vue.prototype.$_hasResource(binding.value)) {
        el.parentNode.removeChild(el);
      }
    })
  }
});

//权限检查方法
Vue.prototype.$_hasResource = function (value) {
  let isExist = false;
  let member = JSON.parse(sessionStorage.getItem('member'));
  var resources = member.resources;
  if (resources === undefined || resources === null) {
    return false
  }
  for (let i = 0; i < resources.length; i++) {
    if (resources[i] === value) {
      isExist = true;
      break;
    }
  }
  return isExist;
};

new Vue({
  el: '#app',
  store,
  router,
  template: '<App/>',
  components: { App }
});
